﻿using System;

class Solution
{
    static void Main()
    {
        //Console.SetIn(new System.IO.StreamReader("input.txt"));

        string whd = Console.ReadLine();
        string[] coordinates = whd.Split(new char[] { ' ' });

        int w = int.Parse(coordinates[0]);
        int h = int.Parse(coordinates[1]);
        int d = int.Parse(coordinates[2]);

        char[, ,] cube = new char[h, d, w];

        string slice = "";
        for (int i = 0; i < h; i++)
        {
            slice = Console.ReadLine();

            string[] rows = slice.Split(new char[] { ' ' });

            for (int j = 0; j < d; j++)
            {
                for (int k = 0; k < w; k++)
                {
                    cube[i, j, k] = rows[j][k];
                }
            }
        }

        int numberBombs = int.Parse(Console.ReadLine());

        int[,] bombCoordinates = new int[numberBombs, 4];

        for (int i = 0; i < numberBombs; i++)
        {
            string bombData = Console.ReadLine();
            string[] bombRows = bombData.Split(new char[] { ' ' });
            for (int j = 0; j < 4; j++)
            {
                bombCoordinates[i, j] = int.Parse(bombRows[j]);
            }
        }

        int totalDistroyed = 0;
        int[] lettersCount = new int[26];

        for (int i = 0; i < numberBombs; i++)
        {
            DetonateBomb(bombCoordinates[i, 0], bombCoordinates[i, 1], bombCoordinates[i, 2], bombCoordinates[i, 3], ref cube, ref totalDistroyed, ref lettersCount);
            BlocksFall(ref cube, bombCoordinates[i, 0], bombCoordinates[i, 1], bombCoordinates[i, 2], bombCoordinates[i, 3]);
        }

        Console.WriteLine(totalDistroyed);

        for (int i = 0; i < 26; i++)
        {
            if (lettersCount[i] > 0)
                Console.WriteLine("{0} {1}", (char)(i + 65), lettersCount[i]);
        }
    }

    static void BlocksFall(ref char[, ,] cube, int bombW, int bombH, int bombD, int bombP)
    {
        //cube[h, d, w]

        int wLowerBoundery = Math.Max(bombW - bombP, 0);
        int wUpperBoundery = Math.Min(bombW + bombP + 1, cube.GetLength(2));

        for (int i = wLowerBoundery; i < wUpperBoundery; i++)
        {
            int dLowerBoundery = Math.Max(bombD - bombP, 0);
            int dUpperBoundery = Math.Min(bombD + bombP + 1, cube.GetLength(1));
            for (int j = dLowerBoundery; j < dUpperBoundery; j++)
            {
                int height = 0;
                int mode = 0;
                int holeLower = 0;
                int holeUpper = 0;
                while ((height < cube.GetLength(0)) && (mode < 2))
                {
                    if (mode == 0)
                    {
                        if (cube[height, j, i] == ' ')
                        {
                            holeLower = height;
                            mode = 1;
                        }
                    }
                    else
                    {
                        if (cube[height, j, i] != ' ')
                        {
                            holeUpper = height;
                            mode = 2;
                        }
                    }
                    height++;
                }

                if (holeUpper > 0)
                {
                    int k = holeUpper;
                    while ((k < cube.GetLength(0)) && (cube[k, j, i] != ' '))
                    {
                        cube[holeLower, j, i] = cube[k, j, i];
                        cube[k, j, i] = ' ';
                        holeLower++;
                        k++;
                    }
                }
            }
        }
    }

    static float CalcDistance(int bombH, int bombD, int bombW, int i, int j, int k)
    {
        return (float)Math.Sqrt((double)((bombH - i) * (bombH - i) + (bombD - j) * (bombD - j) + (bombW - k) * (bombW - k)));
    }

    static void DetonateBomb(int bombW, int bombH, int bombD, int bombP, ref char[, ,] cube, ref int totalDistroyed, ref int[] lettersCount)
    {
        int hLowerBoundery = Math.Max(bombH - bombP, 0);
        int hUpperBoundery = Math.Min(bombH + bombP + 1, cube.GetLength(0));

        for (int i = hLowerBoundery; i < hUpperBoundery; i++)
        {
            int dLowerBoundery = Math.Max(bombD - bombP, 0);
            int dUpperBoundery = Math.Min(bombD + bombP + 1, cube.GetLength(1));

            for (int j = dLowerBoundery; j < dUpperBoundery; j++)
            {
                int wLowerBoundery = Math.Max(bombW - bombP, 0);
                int wUpperBoundery = Math.Min(bombW + bombP + 1, cube.GetLength(2));

                for (int k = wLowerBoundery; k < wUpperBoundery; k++)
                {
                    if (CalcDistance(bombH, bombD, bombW, i, j, k) <= bombP)
                    {
                        if (cube[i, j, k] != ' ')
                        {
                            lettersCount[cube[i, j, k] - 'A']++;
                            totalDistroyed++;
                        }
                        cube[i, j, k] = ' ';
                    }
                }
            }
        }
    }
}
